package com.feishi.core.util.bitbyte.dbc;

import com.feishi.core.util.common.StringUtil;
import lombok.Data;

import java.util.List;

@Data
public class DBCSignal {
    private final String signalName;
    private final int startBit;
    private final int length;
    private final String reciever;
    private final boolean orderType;
    private final boolean unsigned;
    private final double factor;
    private final int offset;
    private final String unit;
    private final double min;
    private final double max;

    //BCM_ReverseLightSts : 0|1@0+ (1,0) [0|1] "" GW
    public DBCSignal(String dbcSignalStr) {
        System.out.println(dbcSignalStr);
        String digP="\\-?[\\d]+(.\\d+)?([Ee][\\+\\-]?\\d+)?";


        List<String> result= StringUtil.matchAll("^\\s+"+DBCDefine.SG_+"\\s+([^ ]+) : " +
                "(\\d+)\\|(\\d+)@(\\d+)(\\+?)\\s+" +
                "\\(([^,]+),([^\\)]+)\\)\\s+" +
                "\\[([^\\|]+)\\|([^\\]]+)\\]\\s+" +
                "\"([^\"]*)\"\\s+" +
                "(.*)$",
                dbcSignalStr);
        if(result.size()==0){
            System.err.println(111);
        }

        this.signalName = result.get(0);
        this.startBit= Integer.parseInt(result.get(1));
        this.length= Integer.parseInt(result.get(2));
        this.orderType= "1".equals(result.get(3));
        this.unsigned= "+".equals(result.get(4));
        this.factor =Double.parseDouble( result.get(5));
        this.offset =  Integer.parseInt(result.get(6));
        this.min=Double.parseDouble( result.get(7));
        this.max=Double.parseDouble( result.get(8));
        this.unit = result.get(9);
        this.reciever=result.get(10);
    }
}
